<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>第一题</title>
    <script>
        //已知数组 求和
        var aa = function () {


            var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
            var num = 0;
            //for遍历数组
            for (var i = 0; i < arr.length; i++) {
                num= num + parseInt(arr[i]);

            }
            alert(num);
        };
        window.onload = function () {


            document.getElementById('btn').onclick = function () {
                aa();
            }
        }

    </script>

</head>
<body>
<p>机试第一题</p>
<button id="btn">考试</button>
<p>代码示例</p>
<pre>
      &lt;script&gt;
        //已知数组 求和
        var aa = function () {


            var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
            var num = 0;
            //for遍历数组
            for (var i = 0; i < arr.length; i++) {
                num= num + parseInt(arr[i]);
            }
             alert(num);
        };
        window.onload = function () {


            document.getElementById('btn').onclick = function () {
                aa();
            }
        }

    &lt;/script&gt;
</pre>
</body>
</html>